using System;
using System.Globalization;

namespace PickGold.Charting.Design
{
	internal class LegendCellCollectionEditor : ChartCollectionEditor
	{
		public LegendCellCollectionEditor()
			: base(typeof(LegendCellCollection))
		{
		}

		protected override object CreateInstance(Type itemType)
		{
			if ((base.Context != null) && (base.Context.Instance != null))
			{
				LegendItem instance = base.Context.Instance as LegendItem;
				if (instance != null)
				{
					int num = instance.Cells.Count + 1;
					string str = "Cell" + num.ToString(CultureInfo.InvariantCulture);
					bool flag = true;
					while (flag)
					{
						flag = false;
						foreach (LegendCell cell in instance.Cells)
						{
							if (cell.Name == str)
							{
								flag = true;
							}
						}
						if (flag)
						{
							num++;
							str = "Cell" + num.ToString(CultureInfo.InvariantCulture);
						}
					}
					LegendCell cell2 = new LegendCell();
					cell2.Name = str;
					return cell2;
				}
			}
			return base.CreateInstance(itemType);
		}
	}
}

